package com.geekstudy.week8;


import com.atomikos.icatch.jta.UserTransactionImp;
import com.atomikos.icatch.jta.UserTransactionManager;
import com.atomikos.jdbc.AtomikosDataSourceBean;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;


@SpringBootApplication
public class Week8DemoMain {

    static Logger logger = LoggerFactory.getLogger(Week8DemoMain.class);

    public static void main(String[] args) {

        ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(Week8DemoMain.class, args);
        logger.info(" beanCount:{} ", configurableApplicationContext.getBeanDefinitionCount());

        // 作业 6
        checkShardingSphere(configurableApplicationContext);


    }

    public static void checkShardingSphere(ConfigurableApplicationContext configurableApplicationContext)  {

        ShardingSphereDataSource shardingSphereDataSource = configurableApplicationContext.getBean(ShardingSphereDataSource.class);
        logger.info(" shardingSphereDataSource:{} ", shardingSphereDataSource);


        AtomikosDataSourceBean atomikosDataSourceBean = configurableApplicationContext.getBean(AtomikosDataSourceBean.class);
        logger.info(" atomikosDataSourceBean testQuery:{} ", atomikosDataSourceBean.getTestQuery());

        UserTransactionManager userTransactionManager = configurableApplicationContext.getBean("userTransactionManager", UserTransactionManager.class);

        // UserTransactionImp userTransactionImp = configurableApplicationContext.getBean("userTransactionImp", UserTransactionImp.class);

        // com.atomikos.jdbc.internal.AtomikosSQLException: Property 'uniqueResourceName' cannot be null
        logger.info(" info");

    }
}
